﻿using AnesSystem.Services;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// 麻醉单监测与治疗
    /// </summary>
    public partial class AnesOperInfoCtrl : UserControl
    {
        public AnesOperInfoCtrl()
        {
            InitializeComponent();
            this.DataContext = AnesOperInfoCtrlViewModel.Instance;

            this.Loaded += AnesOperInfoCtrl_Loaded;
            mzxgc.GotFocus += mzxgn_CheckChanged;
            mzxgn.GotFocus += mzxgn_CheckChanged;
            ShuHouztGetValue();
            InitRadioButton();
        }

        private void InitRadioButton()
        {
            new RadioButtonHelper().ChangeRadioSatus(pcia, pcna, pcea, wypca);
            new RadioButtonHelper().ChangeRadioSatus(mzxgc, mzxgn, mzxgy);
        }

        private void AnesOperInfoCtrl_Loaded(object sender, RoutedEventArgs e)
        {



        }
        private void mzxgn_CheckChanged(object sender, RoutedEventArgs e)
        {
            DrugAndEventWindow.Instance.CusContent = new AnesOperInfoPingDing();
            DrugAndEventWindow.Instance.Height = 500;
            DrugAndEventWindow.Instance.Width = 820;
            DrugAndEventWindow.Instance.ShowDialog();

        }
        private void ShuHouztGetValue()
        {
            List<string> arList = DataManager.Instance.GetXMLTableValue(DataManager.Instance.CurrentPatientLink, "NanTongShuQianFangShi", "pcia", "shztw", "pcea", "shzty");
            bool pcia = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.PCIA;
            bool pcea = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.PCEA;
            bool pcna = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.PCNA;
            bool wypca = DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.WyPCA;
            if (!pcea && !pcia && !pcna && !wypca)
            {
                for (int i = 0; i < arList.Count; i++)
                {

                    if (arList[i].Equals("True"))
                    {
                        switch (i)
                        {
                            case 0:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.PCIA = true;
                                break;
                            case 1:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.PCNA = true;
                                break;
                            case 2:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.PCEA = true;
                                break;
                            case 3:
                                DataManager.Instance.CurrentPatientLink.AnesthesiaRecord.WyPCA = true;
                                break;

                        }
                    }

                }
            }
            return;
        }
        public int TextFontSize
        {
            get { return (int)GetValue(TextFontSizeProperty); }
            set { SetValue(TextFontSizeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for TextFontSize.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TextFontSizeProperty =
            DependencyProperty.Register("TextFontSize", typeof(int), typeof(AnesOperInfoCtrl), new PropertyMetadata(15));



        private void wrapText_ValueChanged(object sender, EventArgs e)
        {
            string text = wrapText.Value.ToString();
            if (text.Length <= 270)
            {
                TextFontSize = 15;
            }
            else if (text.Length > 270 && text.Length <= 340)
            {
                TextFontSize = 14;
            }
            else if (text.Length > 340 && text.Length <= 380)
            {
                TextFontSize = 13;
            }
            else
            {
                TextFontSize = 12;
            }
        }
    }
}
